package unipampa.extensions.games.pampaPife;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;

public class TratarCartas extends BaseClientRequestHandler{
	public void handleClientRequest(User usuario, ISFSObject params){
		PampaPifeExtension gameExt = (PampaPifeExtension) getParentExtension();
		String cartaStr[] = {"c1","c2","c3","c4","c5","c6","c7","c8","c9"};
		String cartaStrCmp[] = {"v","n","b"};
		Carta cartas[] = new Carta[9];

		// Pegando as cartas
		cartas = gameExt.baralho.pegaCartas(usuario.getId());
		
		SFSObject respObj = new SFSObject();
		for (int i=0;i<9;i++){
			respObj.putInt(cartaStr[i]+cartaStrCmp[0], cartas[i].getValor());
			respObj.putInt(cartaStr[i]+cartaStrCmp[1], cartas[i].getNaipe());
			respObj.putInt(cartaStr[i]+cartaStrCmp[2], cartas[i].getBaralho());
		}
		trace("Enviando cartas para "+ usuario.getName());
		send("cartas", respObj, usuario );
	}
}
